
var geocoder,map,marker = null;

function getLatLng(){
	var address = $("#address").val();
	var addurl=url+"activity/activitymap.do?address="+escape(address);
	var iWidth=500; //弹出窗口的宽度;<BR>
	var iHeight=550; //弹出窗口的高度;
	var iTop = (window.screen.availHeight-30-450)/2; //获得窗口的垂直位置;<BR>
	var iLeft = (window.screen.availWidth-10-500)/2; //获得窗口的水平位置;<BR>
	window.open(addurl,"",'height='+iHeight+',,innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');
	//window.open(url,"","width=500,height=450");
}

function getAddressAgain()
{
	var address = $("#txdz2").val();
	codeAddress(address);
}

function initMap() {
       var center = new soso.maps.LatLng(31.301726,120.618212);
	    map = new soso.maps.Map(
            document.getElementById("map"),
            {
                center: center,
                zoomLevel: 15,
                draggable: true,
                scrollWheel: true,
                zoomInByDblClick: true
            });
         var navControl = new soso.maps.NavigationControl({
                   align: soso.maps.ALIGN.TOP_LEFT,
                   margin: new soso.maps.Size(5, 15), 
                   map: map
        });
        geocoder = new soso.maps.Geocoder();
        
        soso.maps.Event.addListener(
		map,
		'click',
		function(event){
			var lat=event.latLng.getLat();
			var lng=event.latLng.getLng();
			$("#latlngText2").val(lat+","+lng);
			if(marker!=null){
				marker.setMap(null);
			}
			marker= new soso.maps.Marker({
					position:new soso.maps.LatLng(lat, lng), 
					map: map
			});
			
	});
	
	var address=GetQueryString("address");
	$("#txdz2").val(address);
	codeAddress(address);

}

function setLatLng(latlng){

	$("#coord").val(latlng);
	
}

function codeAddress(address) {
    if(address==""){return false;}
    geocoder.geocode({'address': '苏州,'+address}, function(results, status) {
        if (status == soso.maps.GeocoderStatus.OK) {
			$("#latlngText2").val(results.location.getLat()+","+results.location.getLng());
            
            if (marker != null) {
                marker.setMap(null);
            }
            marker = new soso.maps.Marker({
                map: map,
                position:results.location
            });
            map.setCenter(results.location);
        } else {
            alert("检索没有结果，请重新获取坐标！");
        }
    });
}

 function GetQueryString(address) { 
    var reg = new RegExp("(^|&)"+ address +"=([^&]*)(&|$)"); 
    var r = window.location.search.substr(1).match(reg); 
    if (r!=null){return unescape(r[2]);}
    return null; 
} 